﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Xiaov.SmartWeb.Model.Domain
{
    public class FileView
    {
        public string Name { get; set; }
        public string CreateTime { get; set; }
        public string FilePath { get; set; }        

        /// <summary>
        /// 根据扩展名得到目录下的所有文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="ext"></param>
        /// <returns></returns>
        public List<FileView> GetFileListByExtentionName(string path, string ext)
        {
            string[] strlist1 = Directory.GetFiles(path);
            List<FileView> list = new List<FileView>();
            for (int i = 0; i < strlist1.Length; i++)
            {                
                FileInfo f = new FileInfo(strlist1[i]);
                if (f.Extension == ext)
                {
                    FileView fview = new FileView();
                    fview.Name = f.Name;
                    fview.CreateTime = f.CreationTime.ToString();
                    fview.FilePath = f.FullName;
                    list.Add(fview);
                }
            }
            return list;
        }

        /// <summary>
        /// 根据扩展名得到目录下的所有文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="ext"></param>
        /// <returns></returns>
        public List<FileView> GetFileListByPreName(string path, string preName)
        {
            string[] strlist1 = Directory.GetFiles(path);
            List<FileView> list = new List<FileView>();
            for (int i = 0; i < strlist1.Length; i++)
            {
                FileInfo f = new FileInfo(strlist1[i]);
                if (f.Name.StartsWith(preName))
                {
                    FileView fview = new FileView();
                    fview.Name = f.Name;
                    fview.CreateTime = f.CreationTime.ToString();
                    fview.FilePath = f.FullName;
                    list.Add(fview);
                }
            }
            return list;
        }
    }
}
